package com.goldgov.basedata.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goldgov.basedata.dao.IBaseDataOrgDao;
import com.goldgov.basedata.service.BaseDataOrg;
import com.goldgov.basedata.service.IBaseDataOrgService;
@Service
public class BaseDataOrgServiceImpl implements IBaseDataOrgService {
	@Autowired
	private IBaseDataOrgDao baseDataOrgDao;
	@Override
	public void addBaseDataOrg(BaseDataOrg baseDataOrg) {
		if(baseDataOrg.getOrganizationIds()!=null&&baseDataOrg.getOrganizationIds().length>0) {
			//循环机构
			for(String orgId:baseDataOrg.getOrganizationIds()) {
				baseDataOrg.setOrganizationId(orgId);
				//循环字典
				if(baseDataOrg.getDataIDs()!=null && baseDataOrg.getDataIDs().length>0) {
					for(String id:baseDataOrg.getDataIDs()) {
						baseDataOrg.setDataID(id);
						//已存在不添加
					Integer count=baseDataOrgDao.findBaseDataOrgCount(baseDataOrg.getDataID(), baseDataOrg.getOrganizationId());
					if(count==0)baseDataOrgDao.addBaseDataOrg(baseDataOrg);
					}
				}
			}
		}
	}
	
	@Override
	public int deleteBaseDataOrg(String[] dataIDs, String organziationId) {
		return baseDataOrgDao.deleteBaseDataOrg(dataIDs, organziationId);
	}

	@Override
	public Integer findBaseDataOrgCount(String dataID, String organziationId) {
		return baseDataOrgDao.findBaseDataOrgCount(dataID, organziationId);
	}
	
	
}
